Zadig 文档
Zadig
教程
博客
论坛
关于
中文英文
Zadig
教程
博客
论坛
关于
Zadig v4.2
Loading...
     编辑文档
     反馈问题
     社区讨论

    本页导航

    Custom Workflow Tasks

    This article describes how to use custom tasks in Zadig system to achieve openness of workflows. The following content includes: How to implement custom tasks and how to use custom tasks.

    # Implement Custom Tasks

    Encoding implements custom workflow tasks and puts the code and configuration into the library. The following is a description of the print Hello Zadig tasks as an example.

    Please refer to the documentation for supported code sources: Code Source Information .

    Step 1 : Encoding and implementing the logic of custom tasks and saving them. The source code of this example main.go The content is as follows:

    package main
    
    import (
        "fmt"
        "github.com/spf13/viper"
    )
    
    const (
    	WhoAmI        = "WHO_AM_I"
    	WeatherStatus = "WEATHER_STATUS"
    )
    
    func main() {
        viper.AutomaticEnv()
    
        who_am_i := viper.GetString(WhoAmI)
        weather_status := viper.GetString(WeatherStatus)
        fmt.Printf("Hello %s, today is %s", who_am_i, weather_status)
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    Step 2 : Compile the source code, build a mirror and go to the image registry push The relevant commands and Dockerfile references are as follows:

    Compile source code commands

    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o greeting-bot main.go
    
    1

    Dockerfile content:

    FROM alpine/git:v2.30.2
    
    # https://wiki.alpinelinux.org/wiki/Setting_the_timezone
    RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add tzdata && \
        cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
        echo Asia/Shanghai  > /etc/timezone && apk del tzdata
    
    WORKDIR /app
    ADD greeting-bot .
    ENTRYPOINT ["/app/greeting-bot"]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    Mirror construction and push command:

    docker build -f Dockerfile --tag koderover.tencentcloudcr.com/koderover-public/greeting-bot:amd64
    docker push koderover.tencentcloudcr.com/koderover-public/greeting-bot:amd64
    
    1
    2

    Step 3 : Write a task configuration file in the YAML format and submit the YAML file to the code base. The YAML configuration file greeting-bot.yaml of this example is as follows:

    name: "Print Hello Zadig"           # Task name
    category: "build"                   # Task type
    version: "v0.0.1"                   # Task version
    description: "Print Hello Zadig"           # Task description
    image: koderover.tencentcloudcr.com/koderover-public/greeting-bot:amd64 # The image built in the previous step
    
    inputs:                             # Variables that can be filled in Zadig
      - name: who_am_i                  # Variable name
        description: "who am i"         # Variable description
        type: string                    # Variable type, supports string (single-line text), text (multi-line text) and choice (single-choice)
        default: "Zadig"                # Variable default value
      - name: weather_status
        description: "what's the weather like today"
        type: choice                    # choice variable type
        choice_option:                  # choice variable type optional value
        - "sunny"
        - "cloudy"
        - "rainy"
        default: "sunny"               # choice variable type default value
    
    envs:                               # Environment variables, automatically injected as environment variables when the above image container starts, in addition to envs, cmds and args are also supported
      - name: WHO_AM
        value: $(inputs.who_am_i)       # Environment variable value, using $(inputs.who_am_i) form to represent the input in Zadig
      - name: WEATHER_STATUS
        value: $(inputs.weather_status)
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    The directory structure organization in the code base meets the following forms:

    path/to/your/repo                # Code repository root directory
    ├── greeting-bot                 # Task directory, when there are multiple tasks, they are organized in separate directories
    │   └── v0.0.1                   # Version number
    │       └── greeting-bot.yaml    # Task YAML file, the file name and task directory name are kept the same
    
    1
    2
    3
    4

    At this point, a complete custom workflow task has been developed, and let’s look at how to use the task.

    # Using Custom Tasks

    Before using tasks, you need to integrate the code source and image registry in the system and configure the source of workflow tasks:

    1. Refer to the code source integration to integrate the above code library in Zadig
    2. Refer to the image registry integration , the image registry corresponding to the image is integrated in Zadig
    3. The system administrator accesses System Settings -> Plugins , configures the code repository, branch and other information and saves it (i.e.: the code repository and branch where the YAML configuration file is located).

    If the integration source is successful and the task implementation in the code base is changed, just click Sync .

    pipeline_task

    After the configuration is complete, add tasks to the workflow, select tasks and save the workflow. For more advanced functions, please refer to the workflow .

    pipeline_taskpipeline_task

    # Task Configuration YAML Syntax

    # Basic Information

    For example:

    name: "Print Hello Zadig"
    category: "build"
    version: "v0.0.1"
    description: "Print Hello Zadig"
    image: koderover.tencentcloudcr.com/koderover-public/greeting-bot:amd64
    
    1
    2
    3
    4
    5

    Parameter Description:

    • name : Task name, as shown in the figure below.
    • category : Task type, including build (Build), deploy (Deployment), test (Test), project-manager (Project Management), config-change (Configuration Change), data-change (Data Change), release (Publish Policy). Other fields can be entered in double quotes: "This is a custom field"
    • version : The version number of the task
    • description : Task description information, as shown in the figure below
    • image : The mirror address of the task

    pipeline_task

    # inputs

    inputs is used to define the value of the variable that can be passed into the container when configuring the workflow.

    For example:

    inputs:
      - name: who_am_i
        description: "who am i"
        type: string
        default: "Zadig"
      - name: weather_status
        description: "what's the weather like today"
        type: choice
        choice_option:
        - "sunny"
        - "cloudy"
        - "rainy"
        default: "sunny"
      - name: script
        description: Dynamic variable
        type: script
        script: |-
          func GetInputVariables(k1, k2, k3 string) []string {
          return []string{k1, k2, k3}
          }
        call_function: GetInputVariables("a", "b", "c")
        default: ""
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22

    Parameter Description:

    • name : Variable name
    • description : Description information
    • type : Variable type, supported types: string (single-line text), text (multi-line text), choice (single-choice), and script (script)
    • choice_option : When type is choice, optional variable value
    • script : When type is script, script content
    • call_function : When type is script, call function
    • default : Variable default value

    The corresponding relationship between parameters and system fields is shown in the figure below

    pipeline_task

    # envs

    The variable information entered when executing a workflow can be passed into the container through envs. When the task container starts, the content configured in envs is automatically injected.

    For example:

    envs:
      - name: WHO_AM_I
        value: $(inputs.who_am_i)
      - name: WEATHER_STATUS
        value: $(inputs.weather_status)
    
    1
    2
    3
    4
    5

    Parameter Description:

    • name : Environment variable name
    • value : Environment variable value, use $ ( inputs.who_am_i ) form to represent the input in Zadig

    # cmds and args

    If you need to modify the startup command of the container, you can configure the cmds and args parameters.

    Give an example

    cmds:
    - "/bin/sh"
    - "-c"
    args:
    - "echo $(inputs.CONTENT)" # Configuration content supports use $ ( inputs.who_am_i ) Formal parameters
    
    1
    2
    3
    4
    5

    # More Demo

    The following custom tasks are built-in to be used directly:

    • Jira Issue Status Change Zadig Combine the workflow stage to change the Jira Issue status and connect with project management. The source code is located in jira-updater(opens new window) .
    • Execute Jenkins Job : Pass in Jenkins build parameters, trigger the specified Jenkins Job execution, the source code is located in jenkins-runner(opens new window) .
    • MySQL Database Change : Execute SQL statement for the MySQL database to realize the linkage change of data and code changes, and the source code is located in mysql-runner(opens new window) .

    In addition, a workflow task shared code base is also opened: koderover/zadig-jobs(opens new window) , which contains several demo implementations and scenario descriptions for developers to use and refer to.

    ← Custom Account SystemZadig Toolkit→

    资源
    教程
    论坛
    博客
    公司
    关于
    客户故事
    加入我们
    联系我们
    微信扫一扫
    hello@koderover.com

    © 2026 筑栈(上海)信息技术有限公司 沪 ICP 备 19000177 号 - 1

    •  跟随系统
    •  浅色模式
    •  深色模式
    •  阅读模式